package demo.day08;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;

/**
 * @Auther: hjy(lc))
 * @Date: 2022/8/2-08-02-16:01
 * @Description：demo.day08
 */
public class for_use {
    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        list.add(5);

        //直接输出
        System.out.println(list);
        //普通for循环
        for (int i = 0; i < list.size(); i++) {
            System.out.print(list.get(i) + " ");
        }
        System.out.println();
        //增强for循环
        for (Integer integer : list) {
            System.out.print(integer + " ");
        }
        System.out.println();
        //迭代器
        Iterator iterator = list.iterator();
        while(iterator.hasNext()){
            System.out.print(iterator.next());
        }
        System.out.println();
        //转为数组调用Arrays工具类
        System.out.println(Arrays.toString(list.toArray()));
    }
}
